package com.yidu.controller;

import com.yidu.entity.Users;
import com.yidu.service.UsersService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class UsersController {
    @Resource
    UsersService usersService;

    @RequestMapping("/UsersTable")
    public String UsersTable(){
        return "UsersTable";
    }
    @RequestMapping("/Permissions")
    public String Permissions(){
        return "Permissions";
    }
    @RequestMapping("/selectUser")
    public String selectUser(String usersName , String usersPassword){
        System.out.println(usersName);
        System.out.println(usersPassword);
        Users users = usersService.selectUser(usersName, usersPassword);
        System.out.println(users);
        if (users != null){
            return "Permissions";
        }else {
            return "index";
        }
    }
    @RequestMapping("/selectUsers")
    @ResponseBody
    public Map selectUsers(int page, int limit){
        List<Users> usersList = usersService.selectUsers(page, limit);
        Map map = new HashMap();
        map.put("code",0);
        map.put("msg",":");
        map.put("count",100);
        map.put("data",usersList);
        return map;
    }
    @RequestMapping("/insertUsers")
    public void insertUsers(Users users){
        usersService.insertUsers(users);
    }
    @RequestMapping("/updateUsers")
    public void updateUsers(Users users){
        usersService.updateUsers(users);
    }
    @RequestMapping("/deleteUsers")
    public void deleteUsers(int usersId){
        usersService.deleteUsers(usersId);
    }
}
